<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of hoidap_model
 *
 * @author Bui
 */
class Hoidap_model extends CI_Model {

    private $tbl_hoidap = 'gs7s_hoidap';

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }

    function load_all_questions() {
        $this->db->select('id, tieude, noidung');
        $this->db->order_by('id','DESC');
        $query = $this->db->get($this->tbl_hoidap);
        return $query->result_array();
          
    }
    
    public function fetch($limit, $start) {
        $this->db->limit($limit, $start);
        $this->db->order_by('id','DESC');
        $query = $this->db->get($this->tbl_hoidap);
 
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }

    function load_question($id_hoidap) {
        return $this->db->get_where($this->tbl_hoidap, array('id' => $id_hoidap));
    }

    function create_question($data) {
        $this->db->insert($this->tbl_hoidap,$data);
    }
    
    function id_hoidap_thanhvien($id_thanhvien) {
        $this->db->select('id');
        $this->db->from($this->tbl_hoidap);
        $this->db->where('chuquan_id',$id_thanhvien);
        $this->db->order_by('id','DESC');
        return $this->db->get();
    }

    function delete_question($id) {
        $this->db->where('id', $id);
        $this->db->delete($this->tbl_hoidap);
    }
    
    function get_paged_list($limit = 10, $offset = 0) {
        $this->db->order_by('id', 'asc');
        return $this->db->get($this->tbl_hoidap, $limit, $offset);
    }
    
    function count_all() {
        return $this->db->count_all($this->tbl_hoidap);
    }
}

?>
